package com.van.serviceImpl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.van.dao.ProductDao;
import com.van.pojo.Product;
import com.van.service.ProductService;
import com.van.util.MybatisUtil;

public class ProductServiceImp implements ProductService {
	private static SqlSession session = MybatisUtil.getSession();
	private static ProductDao productDao = session.getMapper(ProductDao.class);

	@Override
	public List<Product> getAllProduct() {
		List<Product> products = productDao.selectByAll();
		return products;
	}

	@Override
	public Product getProductById(int id) {
		if(id != 0){
			return productDao.selectById(id);
		}
		return null;
	}

	@Override
	public Product getProductByCode(String code) {
		return productDao.selectByCode(code);
	}

	@Override
	public List<Product> searchProduct(String title) {
		return productDao.selectByTitle(title);
	}

	@Override
	public List<Product> filter(Product product) {
		return productDao.selectByProduct(product);
	}

	@Override
	public void insertRecord(Product product) {
		productDao.insertProduct(product);
	}

}
